home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / v3 / sim.lha / sim / print_inst.c < prev    next >
C/C++ Source or Header  |  1990-04-12  |  6KB  |  168 lines

  1. /************************************************************************
  2. *                                    *
  3. * The SB-Prolog System                            *
  4. * Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987    *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24. #include "inst.h"
  25. #include "sim.h"
  26.  
  27. /* these are macros to use lpcreg as the instruction pointer and to
  28.    parse instruction operands into oprnd1, 2, and 3
  29. */
  30. #define PARSE_P    lpcreg++;
  31. #define PARSE_PSS  lpcreg++;  oprnd1 = *lpcreg++;  oprnd2 = *lpcreg++;
  32. #define PARSE_PC   lpcreg++;  oprnd1 = *(LONG_PTR)lpcreg;  lpcreg += 2;
  33. #define PARSE_PL   lpcreg++;  oprnd1 = *(LONG_PTR)lpcreg;  lpcreg += 2;
  34. #define PARSE_PW   lpcreg++;  oprnd1 = *(LONG_PTR)lpcreg;  lpcreg += 2;
  35. #define PARSE_PA   lpcreg++;  oprnd1 = *(LONG_PTR)lpcreg;  lpcreg += 2;
  36. #define PARSE_PWW  lpcreg++;  oprnd1 = *(LONG_PTR)lpcreg;  lpcreg += 2; \
  37.                               oprnd2 = *(LONG_PTR)lpcreg;  lpcreg += 2;
  38.  
  39. #define PARSE_S    oprnd1 = *lpcreg++;
  40. #define PARSE_SSS  oprnd1 = *lpcreg++; oprnd2 = *lpcreg++; \
  41.                                        oprnd3 = *lpcreg++;
  42. #define PARSE_SC   oprnd1 = *lpcreg++; oprnd2 = *(LONG_PTR)lpcreg; lpcreg += 2;
  43. #define PARSE_SL   oprnd1 = *lpcreg++; oprnd2 = *(LONG_PTR)lpcreg; lpcreg += 2;
  44. #define PARSE_SW   oprnd1 = *lpcreg++; oprnd2 = *(LONG_PTR)lpcreg; lpcreg += 2;
  45. #define PARSE_SA   oprnd1 = *lpcreg++; oprnd2 = *(LONG_PTR)lpcreg; lpcreg += 2;
  46. #define PARSE_SAA  oprnd1 = *lpcreg++; oprnd2 = *(LONG_PTR)lpcreg; lpcreg += 2;\
  47.                                        oprnd3 = *(LONG_PTR)lpcreg; lpcreg += 2;
  48. #define PARSE_BBW  oprnd1 = *(BYTE_PTR)lpcreg++; \
  49.            oprnd2 = *(BYTE_PTR)lpcreg++; \
  50.            oprnd3 = *(LONG_PTR)lpcreg;  lpcreg += 2;
  51. #define PARSE_BBA  oprnd1 = *(BYTE_PTR)lpcreg++; \
  52.            oprnd2 = *(BYTE_PTR)lpcreg++; \
  53.            oprnd3 = *(LONG_PTR)lpcreg;  lpcreg += 2;
  54.  
  55. extern int (*p_routine[])();   /* array of functions */
  56.  
  57. #define PRINTOP1(tp)  fprintf(fd, "\t %x",(tp)oprnd1);  fflush(stdout)
  58. #define PRINTOP2(tp)  fprintf(fd, "\t %x",(tp)oprnd2);  fflush(stdout)
  59. #define PRINTOP3(tp)  fprintf(fd, "\t %x",(tp)oprnd3);  fflush(stdout)
  60.  
  61. print_inst(fd, inst_ptr)
  62. FILE     *fd;
  63. WORD_PTR inst_ptr;
  64. {
  65.    WORD_PTR lpcreg; /* local pc register for macros to use */
  66.    WORD     opcode;
  67.    LONG     i;
  68.  
  69.    lpcreg = inst_ptr;
  70.    if (num_line)
  71.       fprintf(fd, "%x\t", lpcreg);
  72.    opcode = *lpcreg++;
  73.  
  74.    fprintf(fd, xxopcode[opcode].name);
  75.  
  76.    switch (xxopcode[opcode].type) {
  77.       case E  : break;
  78.       case P  : PARSE_P;
  79.                 if (opcode == noop)
  80.            lpcreg += oprnd1;
  81.                 break;
  82.       case PSS: PARSE_PSS;
  83.                 PRINTOP1(WORD);
  84.                 PRINTOP2(WORD);
  85.                 break;
  86.       case PC : PARSE_PW;
  87.                 PRINTOP1(LONG);
  88.                 break;
  89.       case PL : PARSE_PL;
  90.                 PRINTOP1(LONG);
  91.                 break;
  92.       case PW : PARSE_PW;
  93.                 PRINTOP1(LONG);
  94.                 break;
  95.       case PA : PARSE_PA;
  96.                 PRINTOP1(LONG);
  97.                 break;
  98.       case S  : PARSE_S;
  99.                 PRINTOP1(WORD);
  100.                 if (opcode == hash) {
  101.                    fprintf(fd, "\n");
  102.                    for (i = 0; i < oprnd1; i++) {
  103.                       if (num_line)
  104.              fprintf(fd, "%x\t", lpcreg);
  105.                       fprintf(fd, "\t %x\n", *(WORD_PTR)lpcreg);
  106.                       lpcreg++;
  107.                    }
  108.                 }
  109.                 break;
  110.       case SSS: PARSE_SSS;
  111.                 PRINTOP1(WORD);
  112.                 PRINTOP2(WORD);
  113.                 PRINTOP3(WORD);
  114.                 break;
  115.       case SC : PARSE_SW;
  116.                 PRINTOP1(WORD);
  117.                 PRINTOP2(LONG);
  118.                 break;
  119.       case SL : PARSE_SL;
  120.                 PRINTOP1(WORD);
  121.                 PRINTOP2(LONG);
  122.                 break;
  123.       case SW : PARSE_SW;
  124.                 PRINTOP1(WORD);
  125.                 PRINTOP2(LONG);
  126.                 break;
  127.       case SA : PARSE_SA;
  128.                 PRINTOP1(WORD);
  129.                 PRINTOP2(LONG);
  130.                 break;
  131.       case SAA: PARSE_SAA;
  132.                 PRINTOP1(WORD);
  133.                 PRINTOP2(LONG);
  134.                 PRINTOP3(LONG);
  135.                 if (opcode == switchonbound) {
  136.                    fprintf(fd, "\n");
  137.                    if (num_line)
  138.               fprintf(fd, "%x\t", lpcreg);
  139.                    opcode = *lpcreg++;
  140.                    fprintf(fd, xxopcode[opcode].name);
  141.                    PARSE_PA;
  142.                    PRINTOP1(WORD); fprintf(fd, "\n");
  143.                    for (i = 0; i < oprnd3; i++) {
  144.                       if (num_line)
  145.              fprintf(fd, "%x\t", lpcreg);
  146.                       fprintf(fd, "\t %x\n", *lpcreg);
  147.                       lpcreg++;
  148.                    }
  149.                 }
  150.                 break;
  151.       case BBW: PARSE_BBW;
  152.             PRINTOP1(BYTE);
  153.             PRINTOP2(BYTE);
  154.             PRINTOP3(LONG);
  155.                 break;
  156.       case BBA: PARSE_BBW;
  157.         PRINTOP1(BYTE);
  158.         PRINTOP2(BYTE);
  159.         PRINTOP3(LONG);
  160.         break;
  161.    }  /* end switch */
  162.  
  163.    pcreg = (WORD_PTR)lpcreg;
  164.  
  165.    fprintf(fd, "\n");
  166.  
  167. }  /* end of print_inst */
  168.